package com.studysecurity.mysecurity;

import com.studysecurity.mysecurity.auth.AuthenticationService;
import com.studysecurity.mysecurity.user.Role;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import com.studysecurity.mysecurity.auth.RegisterRequest;

@SpringBootApplication
public class MysecurityApplication {

	public static void main(String[] args) {
		SpringApplication.run(MysecurityApplication.class, args);
	}

	@Bean
	public CommandLineRunner commandLineRunner(
			AuthenticationService authenticationService
	){
		return args -> {
			var admin = RegisterRequest.builder()
					.firstname("admin")
					.lastname("admin")
					.email("admin@mail.com")
					.password("password")
					.role(Role.ADMIN)
					.build();
			System.out.println("Admin token: " + authenticationService.register(admin).getToken());

			var manager = RegisterRequest.builder()
					.firstname("manager")
					.lastname("manager")
					.email("manager@mail.com")
					.password("password")
					.role(Role.MANAGER)
					.build();
			System.out.println("manager token: " + authenticationService.register(manager).getToken());
		};
	}
}
